import { approvedColumns } from './list_table.config.js'
import search from './../search/search.js';
import { fetchList, addObj, putObj, profitrule } from '@/api/shop/servicer.js'
import comTitle from "@/views/com/com_title.vue";

export default {
    name: "approved",
    mixins: [search],
    components: {
        comTitle,
    },
    data() {
        return {
            approvedColumns,
            loading: false,
            loadData: [/* {
                id: 1,
                fs: 'http://img3.imgtn.bdimg.com/it/u=1940916231,627575868&fm=26&gp=0.jpg'
            } */],
            page: {
                current: 1,
                total: 0,
                size: 10
            },
            showSizeChanger: true,
            showTotal: total => `共有${total}条`,
            selectedRowKeys: [],  //选中的数组
            selectedRows: [],
            number: 0,
            btn: [
                {
                    title: "新增",
                    isShow: true
                },
            ],
            fenrunList: [
                {
                    status: '30689201643925504',
                    text: 'profitRuleName'
                },
            ],
            visible: false,
            confirmLoading: false,
            ruleForm: {
                state: '01',
                sex: '00',
                isShopowner: '00'
            },
            rules: {},
            labelWidth: '120px',
            searchForm: {}
        }
    },
    filters: {
        state: data => {
            switch (data) {
                case "00":
                    return "停止服务";
                case "01":
                    return "启用服务";
                default:
            }
        },
        sex: data => {
            switch (data) {
                case "00":
                    return "男";
                case "01":
                    return "女";
                default:
            }
        },
    },
    methods: {
        getList(searchForm, page) {
            if (searchForm) {
                this.searchForm = searchForm
            }
            if (page) {
                this.page.current = page
            }
            fetchList(Object.assign({ shopId: this.$store.getters.userInfo.sysUser.ecoUserNo }, searchForm ? searchForm : this.searchForm, this.page,)).then(val => {
                let data = val.data
                this.page = {
                    current: data.current,
                    total: data.total,
                    size: data.size,
                }
                this.loadData = data.records
            })
        },
        onShowSizeChange(current, size) {
            console.log(current, size)
            this.page.current = current
            this.page.size = size
            this.getList()
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectedRows = selectedRows;
            this.number = this.selectedRows.length
        },
        // 清空选中项
        clearSelection() {
            this.selectedRowKeys = []
            this.number = 0
        },
        handler(index) {
            if (index == "0") {
                this.publishToStore()
            }
        },
        // 新增
        publishToStore() {
            this.visible = true
            this.getProfitrule()
        },
        dpedit(row) {
            this.ruleForm = row
            this.visible = true
            this.getProfitrule()
        },
        getProfitrule(){
            profitrule(Object.assign({ profitRuleType: "00" })).then(val => {
                console.log(val.data.records)
                this.fenrunList = val.data.records.map((item) => {
                    return {
                        text: item.profitRuleName,
                        status: item.id,
                    };
                });
            })
        },
        handleOk() {
            this.confirmLoading = true
            console.log(this.$store)
            if (this.ruleForm.id) {
                putObj(Object.assign({ shopId: this.$store.getters.userInfo.sysUser.ecoUserNo }, this.ruleForm)).then(() => {
                    this.handleCancel()
                })
            } else {
                addObj(Object.assign({ shopId: this.$store.getters.userInfo.sysUser.ecoUserNo }, this.ruleForm)).then(() => {
                    this.handleCancel()
                })
            }
        },
        handleCancel() {
            this.visible = false
            this.confirmLoading = false
            this.ruleForm = {
                state: '01',
                sex: '00',
                isShopowner: '00'
            }
        }
    }

} 